package com.aaa.marketresearch.webclient.gwt.domain;


import com.google.gwt.json.client.JSONBoolean;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;

/**
 * @author Nail
 */

public class Goods {

    private Integer id;

    private Long barcode;

    private String name;

    private String description;

    private Boolean countable;

    private String units;

    private Double capacity;

    private Integer demand;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Long getBarcode() {
        return barcode;
    }

    public void setBarcode(Long barcode) {
        this.barcode = barcode;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Boolean getCountable() {
        return countable;
    }

    public void setCountable(Boolean countable) {
        this.countable = countable;
    }

    public String getUnits() {
        return units;
    }

    public void setUnits(String units) {
        this.units = units;
    }

    public Double getCapacity() {
        return capacity;
    }

    public void setCapacity(Double capacity) {
        this.capacity = capacity;
    }

    public Integer getDemand() {
        return demand;
    }

    public void setDemand(Integer demand) {
        this.demand = demand;
    }

    public Goods() {
        this.id = null;
        this.name = "";
        this.barcode = 0L;
        this.description = "";
        this.countable = true;
        this.units = "NONE";
        this.capacity = 0.0;
        this.demand = 0;
    }

    public Goods(JSONObject jObj) {
        this.id = (int)jObj.get("id").isNumber().doubleValue();
        this.name = jObj.get("name").isString().stringValue();
        this.barcode = (long)jObj.get("barcode").isNumber().doubleValue();
        this.description = jObj.get("description").isString().stringValue();
        this.countable = jObj.get("countable").isBoolean().booleanValue();
        this.units = jObj.get("units").isString().stringValue();
        this.capacity = jObj.get("capacity").isNumber().doubleValue();
        this.demand = (int)jObj.get("demand").isNumber().doubleValue();
    }

    public JSONObject getJSON() {
        JSONObject jObj = new JSONObject();
        if (this.id != null) {
            jObj.put("id", new JSONNumber(this.id));
        }
        jObj.put("name", new JSONString(this.name));
        jObj.put("barcode", new JSONNumber(this.barcode));
        jObj.put("description", new JSONString(this.description));
        jObj.put("countable", JSONBoolean.getInstance(this.countable));
        jObj.put("units", new JSONString(this.units));
        jObj.put("capacity", new JSONNumber(this.capacity));
        jObj.put("demand", new JSONNumber(this.demand));

        return jObj;
    }
}
